#include<linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include<linux/fs.h>
#include<linux/slab.h>
#include<linux/timer.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/interrupt.h>

MODULE_AUTHOR("Tan xujia");
MODULE_LICENSE("Dual BSD/GPL");

struct workqueue_test {
    struct work_struct work;
    int delay;
    int count;
}ttest;


struct workqueue_struct *workq = NULL;

void 
delayworkqueue_fn(struct work_struct *work)
{
    printk("workqueue_fn\n");
    if (--ttest.count) {
        queue_delayed_work(workq, &ttest.work, ttest.tdelay);
    }
}

static
int __init hello_init (void)
{
    printk("hello_init\n");
    ttest.count = 10;
    ttest.dealy = 10;
    workq = alloc_workqueue("workq", WQ_UNBOUND, 0);
    INIT_DELAYED_WORK(&ttest.work, delayworkqueue_fn);
    queue_delayed_work(workq, &ttest.work, ttest.tdelay);
    return 0;
}

static
void __exit hello_exit (void)
{
    printk("hello_exit\n");
    destroy_workqueue(workq);
}

module_init(hello_init);
module_exit(hello_exit);


/*
struct workqueue_struct *workq
struct delayed_work
INIT_DELAYED_WORK
queue_delayed_work

alloc_workqueue
destroy_workqueue
*/